<template>
  <div class="container">
    <el-card class="card">
      <template #header>
        <h3>区管理员列表</h3>
      </template>
      <el-form
        ref="form"
        class="demo-form-inline"
        :inline="true"
        :model="queryForm"
        @submit.native.prevent
      >
        <el-form-item>
          <el-input placeholder="ID" />
        </el-form-item>
        <el-form-item>
          <el-input placeholder="姓名" />
        </el-form-item>
        <el-form-item>
          <el-input placeholder="账号" />
        </el-form-item>
        <el-form-item>
          <el-input placeholder="角色" />
        </el-form-item>
        <el-form-item>
          <el-input placeholder="手机号" />
        </el-form-item>
        <el-form-item>
          <el-input placeholder="工号" />
        </el-form-item>
        <el-button type="primary" @click="submitForm('form')">查询</el-button>
        <el-button @click="resetForm('form')">重置</el-button>
      </el-form>
      <el-table
        ref="tableSort"
        v-loading="listLoading"
        :border="border"
        :data="list"
        stripe
        @selection-change="setSelectRows"
      >
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column
          align="center"
          label="序号"
          show-overflow-tooltip
          width="55"
        >
          <!-- 序号内容的列 -->
          <template #default="{ $index }">
            {{ $index + 1 }}
          </template>
        </el-table-column>
        <el-table-column
          v-for="(item, index) in finallyColumns"
          :key="index"
          align="center"
          :label="item.label"
          :sortable="item.sortable"
        >
          <!-- 的列 -->
          <template #default="{ row }">
            <span>{{ row[item.prop] }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          show-overflow-tooltip
          width="150"
        >
          <template #default="{ row }">
            <el-button plain type="white" @click="handleEdit(row)">
              编辑
            </el-button>
            <el-button plain type="danger" @click="handleDelete">
              删除
            </el-button>
          </template>
        </el-table-column>
        <template #empty>
          <el-image
            class="vab-data-empty"
            :src="require('@/assets/empty_images/data_empty.png')"
          />
        </template>
      </el-table>
      <el-pagination
        background
        :current-page="queryForm.pageNo"
        :layout="layout"
        :page-size="queryForm.pageSize"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      />
    </el-card>
  </div>
</template>

<script>
  import { getList, doEdit } from '@/api/table'
  export default {
    data() {
      return {
        options1: [
          { value: '选项1', label: '黄金糕' },
          { value: '选项2', label: '双皮奶' },
          { value: '选项3', label: '蚵仔煎' },
          { value: '选项4', label: '龙须面' },
          { value: '选项5', label: '北京烤鸭' },
        ],
        value1: '',
        checkList: [
          '姓名',
          '账号',
          '服务时间',
          '手机号',
          '工号',
          '区域',
          '角色',
          '状态',
          '能否登陆运维端',
          '添加时间',
          '修改时间',
        ],
        columns: [
          {
            label: '姓名',
            width: 'auto',
            prop: 'order',
            sortable: true,
            disableCheck: true,
          },
          {
            label: '账号',
            width: 'auto',
            prop: 'city',
            sortable: true,
          },
          {
            label: '手机号',
            width: 'auto',
            prop: 'rate',
            sortable: true,
          },
          {
            label: '工号',
            width: '200',
            prop: 'phone',
            sortable: true,
          },
          {
            label: '区域',
            width: 'auto',
            prop: 'number',
            sortable: true,
          },
          {
            label: '角色',
            width: 'auto',
            prop: 'rate',
            sortable: true,
          },
          {
            label: '状态',
            width: 'auto',
            prop: 'rate',
            sortable: true,
          },
          {
            label: '能否登陆运维端',
            width: 'auto',
            prop: 'rate',
            sortable: true,
          },
          {
            label: '添加时间',
            width: 'auto',
            prop: 'rate',
            sortable: true,
          },
          {
            label: '修改时间',
            width: 'auto',
            prop: 'rate',
            sortable: true,
          },
        ],
        list: [],
        imageList: [],
        border: '',
        // 加载状态
        listLoading: false,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        // 初始状态下跳转页面的数据
        queryForm: {
          pageNo: 1,
          pageSize: 10,
          title: '',
        },
      }
    },
    computed: {
      dragOptions() {
        return {
          animation: 600,
          group: 'description',
        }
      },
      finallyColumns() {
        return this.columns.filter((item) =>
          this.checkList.includes(item.label)
        )
      },
    },
    created() {
      this.fetchData()
    },
    methods: {
      handleGL() {},
      handleDelete() {},
      submitForm() {},
      resetForm() {},
      setSelectRows(val) {
        this.selectRows = val
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      handleReset() {},
      handleQuery() {
        this.queryForm.pageNo = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getList(this.queryForm)
        const { list, total } = data
        this.list = list
        const imageList = []
        list.forEach((item) => {
          imageList.push(item.img)
        })
        this.imageList = imageList
        this.total = total
        this.listLoading = false
      },
    },
  }
</script>
